package org.bit.practice01;

public class Demo03 {
    public static void main(String[] args) throws InterruptedException {
        int num = 20;

        // 线程数组
        Thread[] threads = new Thread[num];

        // 创建20个子线程,存入线程数组
        for (int i = 0; i < num; i++) {
            final int n = i;
            threads[i]= new Thread(() -> {
                // 内部类使用外部的变量，必须是final修饰
                System.out.println(n);
            });
        }

        // 启动20个线程
        for (Thread t : threads) {
            t.start();
        }

        // 等待20个线程执行完毕
        for (Thread t : threads) {
            t.join();
        }

        System.out.println("ok");
    }
}
